#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>

using namespace std;

// 1297. 子串的最大出现次数
// https://leetcode.cn/problems/maximum-number-of-occurrences-of-a-substring/description/

class Solution
{
public:
    int maxFreq(string s, int maxLetters, int minSize, int maxSize)
    {
        unordered_map<string, int> recordSubStr;
        int ans = 0;
        string curStr;
        int left = 0;
        unordered_map<char, int> recordCharCount;
        for (int i = 0; i < s.size(); i++)
        {
            curStr.push_back(s[i]);
            recordCharCount[s[i]]++;
            if (i - left + 1 < minSize)
            {
                continue;
            }
            if (recordCharCount.size() <= maxLetters)
            {
                ++recordSubStr[curStr];
                ans = max(recordSubStr[curStr], ans);
            }
            recordCharCount[curStr[0]]--;
            if(recordCharCount[curStr[0]] == 0){
                recordCharCount.erase(curStr[0]);
            }

            curStr.erase(0, 1);
            left++;
        }
        return ans;
    }
};

int main()
{
    Solution solution{};
    solution.maxFreq("aaaa", 1, 3, 3);
    return 0;
}